package exteditapp.state;

import exteditapp.AppletIterator;
import exteditapp.FileDefault;
import exteditapp.action.ActionWaiting;

/**
 * State - file idle or not changed (instantiated then last edit was N seconds ago)
 * @author Arturas Smorgun, arturas@smorgun.lt
 */
public class StateWaiting extends IState {

	/**
	 * Default constructor
	 * @param iterator is system iterator, which performs all actions
	 * @param file this is file, which state we will hold
	 */
	public StateWaiting(AppletIterator iterator, FileDefault file) {
		super(iterator, file);
		start();
	}
	public StateWaiting(AppletIterator iterator, FileDefault file, boolean doRegister){
		super(iterator, file, doRegister);
		start();
	}
	
	public void start(){
		this.setAction(new ActionWaiting());
	}
	
	/**
	 * Handling of new state
	 */
	public boolean handle() {
		//TODO implement idle state handling
		if(this.getLifetime() % 4 == 0)
			this.label = "WAITING FOR CHANGES";
		else if((this.getLifetime()+2) % 4 == 0)
			this.label = "PRESS TO END EDITING";
		if(this.file.getFileAsObject().lastModified() > this.file.getLastModified()){
			System.out.println("EINA!!! "+this.file.getFileAsObject().lastModified()+" "+this.file.getLastModified());
			if(this.file.getModule().getSettings().getParameter("autosaveDisabled").compareTo("true") == 0)
				this.file.setCurrentState(new StateEditingManual(this.getIterator(), this.file));
			else
				this.file.setCurrentState(new StateEditing(this.getIterator(), this.file));
		}
		return false;
	}
	
}
